<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/WEB-INF/template/basicTemplate.xhtml">
	<ui:define name="content">
	<h:inputHidden rendered="#{menuController.userRank != 0}" value="#{menuController.redirect()}"></h:inputHidden>
	<h:inputHidden value="#{menuController.setUrl(request.requestURL)}"></h:inputHidden>
	<h:inputHidden rendered="#{menuController.userRank == 0}">
		<h:panelGrid columns="2" border="1">
			<h:column>
				<h:form>
					<h:panelGrid columns="2" styleClass="inner-table"
						inlinestyle="word-break:break-all">
						<h:outputText value="Name:" />
						<h:inputText styleClass="inputText" id="nameDomain" value="${domainDTO.name}">

						</h:inputText>
						<h:commandButton id="addDomain"
							actionListener="#{domainController.addDomain}" value="Add domain"
							styleClass="button">
							<f:ajax execute="nameDomain"
								render=":mess :formm:table nameDomain"></f:ajax>
						</h:commandButton>
					</h:panelGrid>
				</h:form>
				<br />
				<h:form id="formm">
					<h:panelGrid columns="1" styleClass="inner-table">
						<h:dataTable id="table" value="#{domainController.listOfDomains}"
							var="item" border="10" styleClass="templatetable">
							<h:column>
								<f:facet name="header">
									<h:outputText value="Domain" />
								</f:facet>
								<div align="center"><h:commandLink value="#{item.name}"
									style="#{(item.id eq categoryController.currentDomainId)?'color: red':'color: default'}">
									<f:setPropertyActionListener value="#{item.id}"
										target="#{categoryController.currentDomainId}"></f:setPropertyActionListener>
								</h:commandLink></div>
							</h:column>
							<h:column>
								<f:facet name="header">
									<h:outputText value="Delete" />
								</f:facet>
								<div align="center"><h:selectManyCheckbox
									value="#{domainController.checkbox}" styleClass="inner-table">
									<f:selectItem itemLabel="Delete" itemValue="#{item.id}" />
								</h:selectManyCheckbox></div>
							</h:column>
						</h:dataTable>
						<h:panelGrid columns="2" width="auto" styleClass="inner-table">
							<h:commandButton id="deleteDomain"
								actionListener="#{domainController.deleteDomains}"
								value="Delete domains" styleClass="button"
								onclick="if (!confirm('Are you sure you want to continue?')) return false;">
							</h:commandButton>
						</h:panelGrid>

					</h:panelGrid>
				</h:form>
			</h:column>
			<h:column id="column2"
				rendered="#{categoryController.currentDomainId != -1}">
				<h:form>
					<h:panelGrid columns="2" styleClass="inner-table">
						<h:outputText value="Name:" />
						<h:inputText styleClass="inputText" id="nameCat" value="${categoryDTO.name}" />
						<h:commandButton
							actionListener="#{categoryController.addCategory}"
							value="Add category" styleClass="button">
							<f:ajax execute="nameCat"
								render=":mess :formCat:tableCat nameCat"></f:ajax>
						</h:commandButton>

					</h:panelGrid>
				</h:form>
				<br />
				<h:form id="formCat">
					<h:panelGrid width="100%" styleClass="inner-table">

						<h:dataTable id="tableCat"
							value="#{categoryController.listOfCategories}" var="item"
							border="10" width="100%">
							<h:column>
								<f:facet name="header">
									<h:outputText value="Category" />
								</f:facet>
								<div align="center"><h:outputText value="#{item.name}" />
								</div>
							</h:column>
							<h:column>
								<f:facet name="header">
									<h:outputText value="Delete" />
								</f:facet>
								<div align="center"><h:selectManyCheckbox
									value="#{categoryController.checkbox}" styleClass="inner-table">
									<f:selectItem itemLabel="Delete" itemValue="#{item.id}" />
								</h:selectManyCheckbox></div>
							</h:column>
						</h:dataTable>
						<h:panelGrid columns="2" width="auto" styleClass="inner-table">
							<h:commandButton id="deleteCategories"
								actionListener="#{categoryController.deleteCategories}"
								value="Delete categories" styleClass="button"
								onclick="if (!confirm('Are you sure you want to continue?')) return false;">
							</h:commandButton>

						</h:panelGrid>

					</h:panelGrid>
				</h:form>

			</h:column>
		</h:panelGrid>
	</h:inputHidden>

		<h:messages id="mess" styleClass="errorMessage"></h:messages>
	</ui:define>
</ui:composition>
</html>